package org.shunfeng.service.impl;

import org.shunfeng.dao.DeliveryListDao;
import org.shunfeng.dao.impl.DeliveryListDaoImpl;
import org.shunfeng.pojo.Delivery;
import org.shunfeng.service.DeliveryListService;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DeliveryListServiceImpl implements DeliveryListService {
    private DeliveryListDao deliveryListDao = new DeliveryListDaoImpl();

    @Override
    public List<Delivery> queryDeliveryListByUseId(Integer userId) throws SQLException {
        return deliveryListDao.querydeliveryListByUserId(userId);
    }

    @Override
    public int addDelivery(Integer userId, Map<String, String[]> params) throws SQLException {
        Map<String, String> map = new HashMap<>();

        for(Map.Entry<String, String[]> entry:params.entrySet()){
            map.put(entry.getKey(), entry.getValue()[0]);
        }
        return deliveryListDao.addDelivery(map.get("deliveryName"), map.get("phone"),
                map.get("address"), map.get("sendTime"), Integer.parseInt(map.get("companyId")),
                userId, map.get("state"));
    }
    @Override
    public int deleteDelivery(String uId) throws SQLException {
        return deliveryListDao.deleteDelivery(uId);
    }
    @Override
    public Delivery getUserByDeliveryId(Integer id) throws SQLException{
        return deliveryListDao.queryUserByDeliveryId(id);
    }
    @Override
    public int updateDelivery(Integer userId, Map<String, String[]> params) throws SQLException {

        HashMap<String, String> map = new HashMap<>();
        for(Map.Entry<String, String[]> entry:params.entrySet()){
            map.put(entry.getKey(), entry.getValue()[0]);
        }
        return deliveryListDao.updateDelivery(map.get("deliveryName"), map.get("phone"),
                map.get("address"), map.get("sendTime"), Integer.valueOf(map.get("companyId")),
                userId, map.get("state"), map.get("id"));
    }
}
